package com.shop.service.Impl;

import com.shop.mapper.StatMapper;
import com.shop.service.StatService;
import com.shop.vo.CategorySellAmts;
import com.shop.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName StatServiceImpl
 * @Author xiao宋
 * @Date 21:07  2022/10/13
 * @Version 1.0
 * @Description TODO
 */
@Service
public class StatServiceImpl implements StatService {
    @Autowired
    StatMapper statMapper;

    @Override
    public List<CategorySellAmts> findCategorySell() {
        return statMapper.findCategorySell();
    }

    @Override
    public List<DayStatis> findOrderDayStatis() {
        //        获取一个日期对象
        Calendar calendar = Calendar.getInstance();
        //        把日期往前调  一个月
        calendar.add(Calendar.MONTH, -1);
        Date d = calendar.getTime();
        //        调整日期格式，变成当天 0 点 00
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String date = s.format(d);

        return statMapper.findOrderDayStatis(date);
    }

    @Override
    public List<DayStatis> findUserDayStatis() {
        return statMapper.findUserDayStatis();
    }

    @Override
    public List<DayStatis> findCountByOrder() {
        return statMapper.findCountByOrder();
    }

    @Override
    public List<DayStatis> findPlaceAnOrderUserCount() {
        return statMapper.findPlaceAnOrderUserCount();
    }
}
